// ajax 传送items
import $ from "jquery";
import {url} from "../../util/config";
import {message} from "antd";
import login from "../login";

function getNewLogin(items) {
    return deleteBatchItems(items)
}

export default function deleteBatchItems(items) {
    // alert("items.length:"+items.length)
    let status = null;
    let token = localStorage.getItem("token")

    $.ajax({
        async:false,
        headers: {
            'Accept': "application/json",
            'Authorization': token
        },
        url: url.api_url+`FileList/DelFileContent`,
        type: 'POST',
        contentType:"application/json",
        data: JSON.stringify({
            DELETE_ARR:items
        }
        ),
        success: function (result) {
            status=result.result;
            if(status=="Token過期請重新登錄") {
                login(localStorage.getItem("account"), localStorage.getItem("password"));
                status = getNewLogin(items)
            }else {
                if(status=="ok"){
                    message.success("删除成功")
                }else{
                    if(status=="error"){
                        message.error("删除异常");
                    }else {
                        // warn();
                        let moduleList = ""
                        status.map(item =>{
                            moduleList+=(item.MODULE_NAME+" ")
                        })
                        message.error(moduleList+"下有文件，无法直接删除");
                        status = 'ok'
                    }
                }
            }

        },
        error:function (error) {
            status = "error"
            message.error("请求异常")
        }
    })
    return status;
}
